﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ToolsLayer;
using Webcar.BLL;

namespace Webcar.UI
{
    public partial class FilesPanel : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (this.IsPostBack) return;
                string sql = @"select top 15 a.*,b.name oper_name,CONVERT(varchar(10),filedate,120) as filedate_str
                from bs_files a,v_all_users b
                where a.oper_code = b.account  order by filedate desc";
                this.Repeater1.DataSource = DB.ExecuteDataset(sql);
                this.Repeater1.DataBind();
            }
            catch (Exception ex)
            {
                new CurrentUser().LogError(ex);
            }
        }

        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            HyperLink link = (HyperLink)e.Item.FindControl("hyperlink1");
            DataRowView row = e.Item.DataItem as DataRowView;
            link.NavigateUrl = "~/files/" + row["FileName"].ToString();
            Label label = (Label)e.Item.FindControl("newlabel");
            DateTime date = DateTime.Parse(row["filedate"].ToString());
            label.Visible = (DateTime.Now - date).TotalDays < 7;

        }

    }
}